package net.lab1024.sa.admin.module.flowable.controller;

import jakarta.annotation.Resource;
import net.lab1024.sa.admin.module.flowable.domain.AjaxResult;
import net.lab1024.sa.admin.module.flowable.domain.dto.FlowTaskDto;
import net.lab1024.sa.admin.module.flowable.domain.dto.FlowViewerDto;
import net.lab1024.sa.admin.module.flowable.service.IFlowTaskService;
import net.lab1024.sa.admin.module.flowable.service.IFlowableDeployService;
import net.lab1024.sa.base.common.annoation.NoNeedLogin;
import net.lab1024.sa.base.common.domain.ResponseDTO;
import org.springframework.web.bind.annotation.*;

import java.io.InputStream;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/flowable/test")
public class FlowableTestController {
    @Resource
    private IFlowableDeployService flowableDeployService;

    @Resource
    private IFlowTaskService flowTaskService;

    @NoNeedLogin
    @PostMapping("/start/{procDefId}")
    public ResponseDTO<Object> start(@PathVariable(value = "procDefId") String procDefId,
                                     @RequestBody Map<String, Object> variables) {
        return flowableDeployService.startProcessInstanceById(procDefId, variables);
    }

    @NoNeedLogin
    @GetMapping("/viewer/{procInsId}")
    public ResponseDTO<List<FlowViewerDto>> getFlowViewer(@PathVariable(value = "procInsId") String procInsId) {
        return flowTaskService.getFlowViewer(procInsId);
    }

    @NoNeedLogin
    @GetMapping("/bpmn/{procDefId}")
    public InputStream getBpmnXml(@PathVariable(value = "procDefId") String procDefId) {
        return flowTaskService.diagram(procDefId);
    }

    @NoNeedLogin
    @GetMapping("getRecord/{procInsId}")
    public List<FlowTaskDto> getRecord(@PathVariable(value = "procInsId") String procInsId) {
        return flowTaskService.flowRecord(procInsId);
    }

}
